<script lang="ts">
import { defineComponent, onMounted, onUnmounted } from "vue";
import { useNotification } from "naive-ui";
import type { NotificationApi } from "naive-ui";

// 类型安全声明
declare global {
  interface Window {
    $notification?: NotificationApi;
  }
}

export default defineComponent({
  name: "NotificationProvider",
  setup() {
    const notification = useNotification();

    // 安全挂载全局
    onMounted(() => {
      if (import.meta.env.PROD) {
        console.warn(
          "[Deprecation] Avoid window.$notification in production. " +
          "Use dependency injection instead."
        );
      }
      window.$notification = notification;
    });

    // 组件卸载时自动清理
    onUnmounted(() => {
      delete window.$notification;
    });

    return () => null; // 无渲染组件
  }
});
</script>
